import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import Layouts from '@/layouts'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: () => import('@/components/headerLayout/index.vue'),
    redirect: '/',
    mid: 'business',
    children: [{
      path: '/',
      component: () => import('@/views/business/dashboard'),
      name: 'bizdashboard',
      meta: { title: '甘肃省人民医院医务一网通办', icon: 'user', noCache: true }
    },
    {
      path: '/biz/draft',
      component: () => import('@/views/business/draft'),
      name: 'bizdraft',
      meta: { title: '甘肃省人民医院医务一网通办', icon: 'user', noCache: true }
    },
    {
      path: '/biz/my',
      component: () => import('@/views/business/my'),
      name: 'bizmy',
      meta: { title: '甘肃省人民医院医务一网通办', icon: 'user', noCache: true }
    }, {
      path: '/biz/todo',
      component: () => import('@/views/business/todo'),
      name: 'biztodo',
      meta: { title: '甘肃省人民医院医务一网通办', icon: 'user', noCache: true }
    }, {
      path: '/biz/done',
      component: () => import('@/views/business/done'),
      name: 'bizdone',
      meta: { title: '甘肃省人民医院医务一网通办', icon: 'user', noCache: true }
    }, {
      path: '/biz/ccRecord',
      component: () => import('@/views/business/ccRecord'),
      name: 'bizccRecord',
      meta: { title: '甘肃省人民医院医务一网通办', icon: 'user', noCache: true }
    }, {
      path: '/biz/message',
      component: () => import('@/views/business/message'),
      name: 'bizmessage',
      meta: { title: '甘肃省人民医院医务一网通办', icon: 'user', noCache: true }
    }, {
      path: '/biz/app',
      component: () => import('@/views/business/app'),
      name: 'bizapp',
      meta: { title: '甘肃省人民医院医务一网通办', icon: 'user', noCache: true }
    }
    ]
  },

  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: '个人中心',
        meta: { title: '个人中心', icon: 'user', noCache: true }
      }
    ]
  },
  {
    path: '/xjsxxm',
    hidden: false,
    children: [
      {
        path: '/home',
        hidden: false,
        component: () => import('@/views//menu-nesting/index.vue'),
        name: 'ProjectHome',
        mid: 'xjsxxm',
        meta: {
          title: '首页',
          icon: 'edit',
          activeMenu: '',
          noCache: true
        },
        children: [
          {
            path: '/project/apply',
            hidden: false,
            children: [],
            name: 'Apply',
            mid: 'xjsxxm',
            component: () => import('@/views/xjsxxm/apply/home.vue'),
            meta: {
              title: '首页',
              icon: 'server',
              activeMenu: '',
              noCache: true
            }
          }
        ]
      },
      {
        path: '/project',
        hidden: false,
        component: () => import('@/views//menu-nesting/index.vue'),
        children: [

          {
            path: '/xjsxxm/apply/my',
            hidden: false,
            component: () => import('@/views/xjsxxm/apply/my.vue'),
            children: [],
            name: 'MyApply',
            mid: 'xjsxxm',
            meta: {
              title: '我的申报',
              icon: 'log',
              activeMenu: '',
              noCache: true
            }
          },
          {
            path: '/xjsxxm/apply/myDraft',
            hidden: false,
            component: () => import('@/views/xjsxxm/apply/myDraft.vue'),
            children: [],
            name: 'MyDraft',
            mid: 'xjsxxm',
            meta: {
              title: '我的草稿',
              icon: 'log',
              activeMenu: '',
              noCache: true
            }
          },
          {
            path: '/xjsxxm/apply/activated',
            hidden: false,
            component: () => import('@/views/xjsxxm/apply/activated.vue'),
            children: [],
            name: 'Activated',
            mid: 'xjsxxm',
            meta: {
              title: '已开通项目',
              icon: 'log',
              activeMenu: '',
              noCache: true
            }
          },
          {
            path: '/xjsxxm/apply/pendApproval',
            hidden: false,
            component: () => import('@/views/xjsxxm/apply/pendApproval.vue'),
            children: [],
            name: 'PendApproval',
            mid: 'xjsxxm',
            meta: {
              title: '待我审批的',
              icon: 'log',
              activeMenu: '',
              noCache: true
            }
          },
          {
            path: '/xjsxxm/apply/myApproval',
            hidden: false,
            component: () => import('@/views/xjsxxm/apply/myApproval.vue'),
            children: [],
            name: 'MyApproval',
            mid: 'xjsxxm',
            meta: {
              title: '我已审批的',
              icon: 'log',
              activeMenu: '',
              noCache: true
            }
          }
        ],
        name: 'ProjectApply',
        mid: 'xjsxxm',
        meta: {
          title: '项目申报',
          icon: 'edit',
          activeMenu: '',
          noCache: true
        }
      },
      {
        path: '/annual',
        hidden: false,
        component: () => import('@/views//menu-nesting/index.vue'),
        name: 'ProjectAnnual',
        mid: 'xjsxxm',
        meta: {
          title: '项目年审',
          icon: 'edit',
          activeMenu: '',
          noCache: true
        },
        children: [
          {
            path: '/xjsxxm/annual/myAnnual',
            hidden: false,
            component: () => import('@/views/xjsxxm/annual/myAnnual.vue'),
            children: [],
            name: 'MyAnnual',
            mid: 'xjsxxm',
            meta: {
              title: '我申请的年审',
              icon: 'log',
              activeMenu: '',
              noCache: true
            }
          },
          {
            path: '/xjsxxm/annual/myDraft',
            hidden: false,
            component: () => import('@/views/xjsxxm/annual/myDraft.vue'),
            children: [],
            name: 'AnnualMyDraft',
            mid: 'xjsxxm',
            meta: {
              title: '我的年审草稿',
              icon: 'log',
              activeMenu: '',
              noCache: true
            }
          },
          {
            path: '/xjsxxm/annual/doneAnnual',
            hidden: false,
            component: () => import('@/views/xjsxxm/annual/doneAnnual.vue'),
            children: [],
            name: 'DoneAnnual',
            mid: 'xjsxxm',
            meta: {
              title: '已完成年审',
              icon: 'log',
              activeMenu: '',
              noCache: true
            }
          }
        ]
      },
      {
        path: '/stageReview',
        hidden: false,
        component: () => import('@/views//menu-nesting/index.vue'),
        name: 'ProjectStageReview',
        mid: 'xjsxxm',
        meta: {
          title: '阶段评审',
          icon: 'edit',
          activeMenu: '',
          noCache: true
        },
        children: [
          {
            path: '/xjsxxm/stageReview/toConfirmed',
            hidden: false,
            component: () => import('@/views/xjsxxm/stageReview/toConfirmed.vue'),
            children: [],
            name: 'ToConfirmed',
            mid: 'xjsxxm',
            meta: {
              title: '待确认的阶段审批',
              icon: 'log',
              activeMenu: '',
              noCache: true
            }
          },
          {
            path: '/xjsxxm/stageReview/confirmed',
            hidden: false,
            component: () => import('@/views/xjsxxm/stageReview/confirmed.vue'),
            children: [],
            name: 'Confirmed',
            mid: 'xjsxxm',
            meta: {
              title: '已确认的阶段审批',
              icon: 'log',
              activeMenu: '',
              noCache: true
            }
          }
        ]
      },
      {
        path: '/analyse',
        hidden: false,
        component: () => import('@/views//menu-nesting/index.vue'),
        name: 'ProjectAnalyse',
        mid: 'xjsxxm',
        meta: {
          title: '查询分析',
          icon: 'edit',
          activeMenu: '',
          noCache: true
        },
        children: [

          {
            path: '/xjsxxm/analyse/project',
            hidden: false,
            component: () => import('@/views/xjsxxm/analyse/project/index.vue'),
            children: [],
            name: 'AnalyseProject',
            mid: 'xjsxxm',
            meta: {
              title: '新技术项目查询',
              icon: 'log',
              activeMenu: '',
              noCache: true
            }
          },
          {
            path: '/xjsxxm/analyse/annual',
            hidden: false,
            component: () => import('@/views/xjsxxm/analyse/annual/index.vue'),
            children: [],
            name: 'AnalyseAnnual',
            mid: 'xjsxxm',
            meta: {
              title: '年审查询',
              icon: 'log',
              activeMenu: '',
              noCache: true
            }
          }
        ]
      },
      {
        path: '/history',
        hidden: false,
        component: () => import('@/views//menu-nesting/index.vue'),
        name: 'ProjectHistory',
        mid: 'xjsxxm',
        meta: {
          title: '历史项目',
          icon: 'edit',
          activeMenu: '',
          noCache: true
        },
        children: [
          {
            path: '/xjsxxm/history',
            hidden: false,
            component: () => import('@/views/xjsxxm/award/index.vue'),
            children: [],
            name: 'HistoryItem',
            mid: 'xjsxxm',
            meta: {
              title: '项目列表',
              icon: 'log',
              activeMenu: '',
              noCache: true
            }
          }
        ]
      }
    ],
    name: 'Xjsxxm',
    mid: 'xjsxxm',
    meta: {
      'title': '医疗技术管理平台',
      'icon': 'list',
      'activeMenu': '',
      'noCache': true
    },
    component: Layout
  }
]

export const asyncRoutes = []

const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
